﻿using MesServices.StationService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Collections.Specialized.BitVector32;
using static MesServices.MesName;

namespace MesServices
{
    public class UnifiedMes : IMes_PassStation
    {
        StationServiceSoapClient stationService = new StationServiceSoapClient();

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input">plan, banzu, line, user, station, sn, result</param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool AfterTest(Dictionary<MesName, string> input, ref string errMsg)
        {
            bool res = stationService.ML_SS_AfterTestWithTips(input[Plan], input[Banzu], input[Line], input[UserName], input[Station], input[SN], Convert.ToBoolean(input[Result]),ref errMsg);
            if (errMsg.IndexOf("请到下一站") < 0)
            {
                res = false;
                errMsg = "当前条码" + input[SN] + "过站失败，失败原因" + errMsg;
            }
            return res;
        }

        /// <summary>
        /// </summary>
        /// <param name="input">TaskNo、Station、SN</param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool BeforeTest(Dictionary<MesName, string> input, ref string errMsg)
        {
            bool res = stationService.ML_SS_BeforeTest(input[Plan], input[Station], input[SN], ref errMsg);
            if (!res)
            {
                errMsg = "当前条码" + input[SN] + "入站失败，失败原因" + errMsg;
            }
            return res;
        }

        public bool GetPlanName(string SN, ref string planName, ref string errMsg)
        {
            throw new NotImplementedException();

        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="input">planName, banzu, user, station, sn, testData</param>
        /// <param name="errMsg"></param>
        /// <returns></returns>
        public bool UploadErrorInfo(Dictionary<MesName, string> input, ref string errMsg)
        {
            bool res = stationService.ML_SS_UploadTestData(input[Plan],input[Banzu],input[UserName],input[Station],input[SN],input[ErrorMessage], ref errMsg);
            if (!res)
            {
                errMsg = "当前条码" + input[SN] + "上传数据失败，失败原因" + errMsg;
            }
            return res;
        }
    }
}
